package com.example.basic.utils;

import android.annotation.SuppressLint;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {

    @SuppressLint("SimpleDateFormat")
    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static String getDateString(Date date) {
        String format = sdf.format(date);
        return format;
    }

    /**
     * SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
     * @param sDate
     * @return
     */
    private static long getDate(String sDate) throws ParseException {
        Date date = sdf.parse(sDate);
        return date.getTime();
    }

    public static long getDate(int year, int month, int dayOfMonth) {
        String sDate = year + "-"+ (((month+1)>=10)?(month+1):"0"+(month+1)) +"-"+(dayOfMonth>=10?dayOfMonth:"0"+dayOfMonth) + " 00:00:00";
        try {
            return getDate(sDate);
        } catch (ParseException e) {
            e.printStackTrace();
            return -1;
        }
    }



    public static String getDateString(long date) {
        String format = sdf.format(new Date(date));
        return format;
    }

    private static String getDateStr() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date(System.currentTimeMillis());
        String dateStr = simpleDateFormat.format(date);
        return dateStr;
    }

    /*
    yyyy-MM-dd HH:mm:ss:代表将时间转换为24小时制,例: 2018-06-27 15:24:21
    yyyy-MM-dd hh:mm:ss:代表将时间转换为12小时制,例: 2018-06-27 03:24:21
     */
    private static String getTimeStr() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
        Date date = new Date(System.currentTimeMillis());
        String timeStr = simpleDateFormat.format(date);
        return timeStr;
    }


}
